package com.rftennis.service.impl;



import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rftennis.ao.OrderAo;
import com.rftennis.dao.OrderDao;

import com.rftennis.dto.QueryResult;
import com.rftennis.entity.CustomerEntity;
import com.rftennis.entity.OrderEntity;
import com.rftennis.exception.RftennisException;

import com.rftennis.service.OrderService;

import lombok.NonNull;

import com.common.OrderUtil;
import com.common.StringUtil;
import com.common.validation.AssertThrowService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@Service
public class OrderServiceImpl implements OrderService,AssertThrowService,StringUtil{
	@Autowired
	OrderDao dao;
	
	@Override
	public QueryResult<OrderEntity> selectIdKeyOrder(String customerId,String key, int pageNo, int pageSize) throws Exception {
		// 1 验证参数(参数清理)
				key = trim(key);
				if (key != null) {
					key = escapeForSqlLike(key);
					key="%"+key+"%";
				}
				if (pageNo <= 0) {
					pageNo = 1;
				}
				if (pageSize <= 0) {
					pageSize = 5;
				}
				customerId=$("用户",customerId);
				// 2 执行业务逻辑
					PageHelper.startPage(pageNo, pageSize);
					
					PageInfo<OrderEntity> page=new PageInfo<>(dao.selectByIdKey(customerId, key));
					// 3 组装结果
					QueryResult<OrderEntity> result=new QueryResult<OrderEntity>();
					result.setPageNo(pageNo);
					
					result.setRows(page.getList());
					result.setTotalRows(page.getTotal());
					result.setPageSize(pageSize);
					return result;
	}

	@Override
	public QueryResult<OrderEntity> selectKeyOrder(String key, int pageNo, int pageSize) throws Exception {
		// 1 验证参数(参数清理)
		key = trim(key);
		if (key != null) {
			key = escapeForSqlLike(key);
			key="%"+key+"%";
		}
		if (pageNo <= 0) {
			pageNo = 1;
		}
		if (pageSize <= 0) {
			pageSize = 5;
		}
		
		// 2 执行业务逻辑
			PageHelper.startPage(pageNo, pageSize);
			
			PageInfo<OrderEntity> page=new PageInfo<>(dao.selectByKey(key));
			// 3 组装结果
			QueryResult<OrderEntity> result=new QueryResult<OrderEntity>();
			result.setPageNo(pageNo);
			
			result.setRows(page.getList());
			result.setTotalRows(page.getTotal());
			result.setPageSize(pageSize);
			return result;
	}
}

	
